'use strict';
/**
 * @fileoverview 激活码类型
 * @author sundbcn@gmail.com (sun debing)
 */

var mongoose = require('mongoose');
var _ = require('lodash');
var rewardItemSchema = require('./survive/rewardItemSchema');

var rewardItemSchema = new mongoose.Schema({
    //奖励
    reward: {
        type: Number,
        default: 0
    },

    //奖励类型
    reward_type: {
        type: Number,
        default: 0
    },

    // 奖励数量
    reward_num: {
        type: Number,
        default: 0
    },

    // 奖励值
    reward_value: {
        type: Number,
        default: 0
    },

    // 孔
    hole_num: {
        type: Number,
        default: 0
    }
});

/**
 * 激活码类型
 */
var cdkTypeSchema = new mongoose.Schema({
    // 激活码类型
    cdk_type: {
        type: Number,
        required: true,
        unique: true,
        index: true
    },

    // 奖励信息
    reward_list: [rewardItemSchema],

    // 使用次数限制
    limit_times: {
        type: Number,
        default: 1
    }
});

cdkTypeSchema.methods.getRewardList = function () {
    var list = [];
    _.each(this.reward_list, function (reward_item) {
        list.push({
            reward: 0,
            reward_type: reward_item.reward_type,
            reward_num: reward_item.reward_num,
            reward_value: reward_item.reward_value,
            hole_num: 0
        });
    });
    return list;
};

mongoose.model('CdkType', cdkTypeSchema);
